<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" href="../layui/css/layui.css">
  <link rel="stylesheet" href="../css/custom.form.css">
</head>
<body>
<div class="panel panel-default operation" hidden>
  <div class="panel-heading title"></div>
<div class="layui-card-body">
<form class="layui-form " action="" lay-filter="info" style="width: 700px;margin-top: 10px">
      <input name="tBBH" hidden/>
        <div class="layui-form-item">
      <label class="layui-form-label">由遥感图斑下发</label>
      <div class="layui-input-block">
        <input type="text" name="zTBH" placeholder="请输入由遥感图斑下发" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">选择：生产矿山图斑、建设项目临时用地图斑、自然灾损图斑、历史遗留废弃矿山图斑、废弃矿山图斑</label>
      <div class="layui-input-block">
        <input type="text" name="tBLX" placeholder="请输入选择：生产矿山图斑、建设项目临时用地图斑、自然灾损图斑、历史遗留废弃矿山图斑、废弃矿山图斑" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">矿区所在市</label>
      <div class="layui-input-block">
        <input type="text" name="xZS" placeholder="请输入矿区所在市" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">矿区所在县</label>
      <div class="layui-input-block">
        <input type="text" name="xZX" placeholder="请输入矿区所在县" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">描述图斑所在位置，具体到乡镇村组</label>
      <div class="layui-input-block">
        <input type="text" name="wZ" placeholder="请输入描述图斑所在位置，具体到乡镇村组" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">损毁或恢复治理面积，整数16位，小数2位</label>
      <div class="layui-input-block">
        <input type="text" name="tBMJ" placeholder="请输入损毁或恢复治理面积，整数16位，小数2位" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">浮点型保留6位小数</label>
      <div class="layui-input-block">
        <input type="text" name="kFX" placeholder="请输入浮点型保留6位小数" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">浮点型保留6位小数</label>
      <div class="layui-input-block">
        <input type="text" name="kFY" placeholder="请输入浮点型保留6位小数" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">该图斑所涉及项目的名称，未涉及填“无”</label>
      <div class="layui-input-block">
        <input type="text" name="xMMC" placeholder="请输入该图斑所涉及项目的名称，未涉及填“无”" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">有无合法用地手续，0-无，1-有</label>
      <div class="layui-input-block">
        <input type="yDSX" name="yDSX" placeholder="请输入有无合法用地手续，0-无，1-有" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">选代码，见填表excel表格说明</label>
      <div class="layui-input-block">
        <input type="text" name="tBSX" placeholder="请输入选代码，见填表excel表格说明" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">全国第三次土地调查中的地类代码</label>
      <div class="layui-input-block">
        <input type="text" name="sDDL" placeholder="请输入全国第三次土地调查中的地类代码" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">选代码，A-国有土地所有权，B-集体土地所有权</label>
      <div class="layui-input-block">
        <input type="text" name="ownership" placeholder="请输入选代码，A-国有土地所有权，B-集体土地所有权" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">选代码，A-国有土地使用权；B-集体土地使用权；C-其他</label>
      <div class="layui-input-block">
        <input type="text" name="sYQ" placeholder="请输入选代码，A-国有土地使用权；B-集体土地使用权；C-其他" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">选代码，A-未治理；B-正在治理；C-已恢复治理</label>
      <div class="layui-input-block">
        <input type="text" name="zLQK" placeholder="请输入选代码，A-未治理；B-正在治理；C-已恢复治理" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">实地核查测量的治理面积</label>
      <div class="layui-input-block">
        <input type="text" name="zLMJ" placeholder="请输入实地核查测量的治理面积" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">切图文件存放的物理地址</label>
      <div class="layui-input-block">
        <input type="text" name="qTDZ" placeholder="请输入切图文件存放的物理地址" autocomplete="off" class="layui-input">
      </div>
    </div>
  <div class="layui-form-item">
  <div class="layui-input-block">
    <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
    <button  class="layui-btn layui-btn-primary" id="btn_cancel">返回</button>
  </div>
</div>
</form>
</div>
</div>

<div class="table_div">
  <div id="searchParam"  shiro:hasPermission="spottableBase:list">
    <div class="layui-form-item">
      <div class="layui-input-inline">
        <input type="text" id="key" class="layui-input"  autocomplete="off" placeholder="请输入">
      </div>

      <div class="layui-input-inline ">
        <button class="layui-btn" onclick="search()"  id="search">查询</button>
        <button class="layui-btn"   id="export">导出全部</button>
      </div>
    </div>

  </div>
  <table class="layui-table" id="showTable" lay-filter="showTable" ></table>
</div>
<script type="text/html" id="toolbar">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="add"  shiro:hasPermission="spottableBase:add">添加</button>
    <button class="layui-btn layui-btn-sm" lay-event="batchDeleted" shiro:hasPermission="spottableBase:delete">删除</button>
  </div>
</script>
<script type="text/html" id="tool">
  <a class="layui-btn layui-btn-xs" lay-event="edit" shiro:hasPermission="spottableBase:update">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" shiro:hasPermission="spottableBase:delete">删除</a>
</script>

</body>
</html>
<script src="../layui/layui.all.js"></script>
<script src="../js/core.util.js"></script>
<script>
  //获取token
  var token = CoreUtil.getData("access_token");
  //地址栏转义token中的#号
  var tokenQuery = token.replace("#", "%23");
  var tableIns1;
  var table = layui.table;
  var form = layui.form;
  var layer = layui.layer;
  var $ = jQuery = layui.jquery;
  var laydate = layui.laydate;

  layui.use(['table', 'layer', 'laydate'], function () {

    //加载table
    tableIns1 = table.render({
      elem: '#showTable'
      , contentType: 'application/json'
      , headers: {"authorization": token}
      , page: true //开启分页
      , url: '/spottableBase/listByPage' //数据接口
      , method: 'POST'
      , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
        return {
          "code": res.code, //解析接口状态
          "msg": res.msg, //解析提示文本
          "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
          "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
        }
      }
      , cols: [
        [
          {type: 'checkbox'},
          {field: 'tBBH', title: '由遥感图斑下发', sort: true},
          {field: 'zTBH', title: '由遥感图斑下发', sort: true},
          {field: 'tBLX', title: '选择：生产矿山图斑、建设项目临时用地图斑、自然灾损图斑、历史遗留废弃矿山图斑、废弃矿山图斑', sort: true},
          {field: 'xZS', title: '矿区所在市', sort: true},
          {field: 'xZX', title: '矿区所在县', sort: true},
          {field: 'wZ', title: '描述图斑所在位置，具体到乡镇村组', sort: true},
          {field: 'tBMJ', title: '损毁或恢复治理面积，整数16位，小数2位', sort: true},
          {field: 'kFX', title: '浮点型保留6位小数', sort: true},
          {field: 'kFY', title: '浮点型保留6位小数', sort: true},
          {field: 'xMMC', title: '该图斑所涉及项目的名称，未涉及填“无”', sort: true},
          {field: 'yDSX', title: '有无合法用地手续，0-无，1-有', sort: true},
          {field: 'tBSX', title: '选代码，见填表excel表格说明', sort: true},
          {field: 'sDDL', title: '全国第三次土地调查中的地类代码', sort: true},
          {field: 'ownership', title: '选代码，A-国有土地所有权，B-集体土地所有权', sort: true},
          {field: 'sYQ', title: '选代码，A-国有土地使用权；B-集体土地使用权；C-其他', sort: true},
          {field: 'zLQK', title: '选代码，A-未治理；B-正在治理；C-已恢复治理', sort: true},
          {field: 'zLMJ', title: '实地核查测量的治理面积', sort: true},
          {field: 'qTDZ', title: '切图文件存放的物理地址', sort: true},
          {width: 120, toolbar: "#tool", title: '操作'}
        ]
      ]
      , toolbar: '#toolbar'
    });


    //表头工具
    table.on('toolbar(showTable)', function(obj){
      switch(obj.event){
        case 'batchDeleted':
          var checkStatus = table.checkStatus(obj.config.id);
          var data = checkStatus.data;
          if(data.length==0){
            layer.msg("请选择要批量删除的列");
          }else {
            var ids = [];
            $(data).each(function (index,item) {
              ids.push(item.id);
            });
            tipDialog(ids);
          }
          break;
        case 'add':
          $(".table_div").hide();
          $(".operation").show();
          $(".title").html("新增");
          $(".operation input[name=tBBH]").val("");
          $(".operation input[name=zTBH]").val("");
          $(".operation input[name=tBLX]").val("");
          $(".operation input[name=xZS]").val("");
          $(".operation input[name=xZX]").val("");
          $(".operation input[name=wZ]").val("");
          $(".operation input[name=tBMJ]").val("");
          $(".operation input[name=kFX]").val("");
          $(".operation input[name=kFY]").val("");
          $(".operation input[name=xMMC]").val("");
          $(".operation input[name=yDSX]").val("");
          $(".operation input[name=tBSX]").val("");
          $(".operation input[name=sDDL]").val("");
          $(".operation input[name=ownership]").val("");
          $(".operation input[name=sYQ]").val("");
          $(".operation input[name=zLQK]").val("");
          $(".operation input[name=zLMJ]").val("");
          $(".operation input[name=qTDZ]").val("");
          break;
      };
    });
    //列操作
    table.on('tool(showTable)',function (obj) {
      var data = obj.data;
      switch (obj.event) {
        case 'del':
          var ids=[];
          ids.push(data.id);
          tipDialog(ids);
          break;
        case 'edit':
          $(".table_div").hide();
          $(".operation").show();
          $(".title").html("编辑");
          $(".operation input[name=tBBH]").val(data.tBBH);
          $(".operation input[name=zTBH]").val(data.zTBH);
          $(".operation input[name=tBLX]").val(data.tBLX);
          $(".operation input[name=xZS]").val(data.xZS);
          $(".operation input[name=xZX]").val(data.xZX);
          $(".operation input[name=wZ]").val(data.wZ);
          $(".operation input[name=tBMJ]").val(data.tBMJ);
          $(".operation input[name=kFX]").val(data.kFX);
          $(".operation input[name=kFY]").val(data.kFY);
          $(".operation input[name=xMMC]").val(data.xMMC);
          $(".operation input[name=yDSX]").val(data.yDSX);
          $(".operation input[name=tBSX]").val(data.tBSX);
          $(".operation input[name=sDDL]").val(data.sDDL);
          $(".operation input[name=ownership]").val(data.ownership);
          $(".operation input[name=sYQ]").val(data.sYQ);
          $(".operation input[name=zLQK]").val(data.zLQK);
          $(".operation input[name=zLMJ]").val(data.zLMJ);
          $(".operation input[name=qTDZ]").val(data.qTDZ);
          break;
      }
    });

    //导出
    $('#export').on('click', function () {
      //原先分页limit
      var exportParams = {
        limit: 10000,
        key: $("#key").val()
      };
      CoreUtil.sendPost("/spottableBase/listByPage", exportParams, function (res) {
        //初始化渲染数据
        if (res.data != null && res.data.records != null) {
          table.exportFile(tableIns1.config.id, res.data.records, 'xls');
        }
      });
    });

    //删除
    var tipDialog=function (ids) {
      layer.open({
        content: "确定要删除么?",
        yes: function(index, layero){
          layer.close(index); //如果设定了yes回调，需进行手工关闭
          CoreUtil.sendDelete("/spottableBase/delete",ids,function (res) {
            layer.msg(res.msg, {time:1000},function () {
              search();
            });
          });
        }
      });
    };

    //返回
    $("#btn_cancel").click(function() {
      $(".table_div").show();
      $(".operation").hide();
      return false;
    });

    //监听保存
    form.on('submit(submit)', function(data){
      if(data.field.id===undefined || data.field.id===null || data.field.id===""){
        CoreUtil.sendPost("/spottableBase/add",data.field,function (res) {
          $(".table_div").show();
          $(".operation").hide();
          search();
        });
      }else {
        CoreUtil.sendPut("/spottableBase/update",data.field,function (res) {
          $(".table_div").show();
          $(".operation").hide();
          search();
        });
      }

      return false;
    });
  });

  //执行查询
  function search() {
    //这里以搜索为例
    tableIns1.reload({
      where: { //设定异步数据接口的额外参数，任意设
        key: $("#key").val()
      }
      , page: {
        curr: 1 //重新从第 1 页开始
      }
    });
  };
</script>